package com.missilike.core.domain;

import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

@Data
public class AuthUser implements UserDetails {

    private Integer id;

    private String account;

    private String nickName;

    private Boolean isSystemAdmin;

    private List<String> roleList;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        List<GrantedAuthority> auth = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(roleList)) {
            this.isSystemAdmin = roleList.contains("sys_admin");
            for (String authority : roleList) {
                GrantedAuthority grantedAuthority = new SimpleGrantedAuthority(authority);
                auth.add(grantedAuthority);
            }
        }
        return auth;
    }

    @Override
    public String getPassword() {
        return null;
    }

    @Override
    public String getUsername() {
        return null;
    }

    @Override
    public boolean isAccountNonExpired() {
        return false;
    }

    @Override
    public boolean isAccountNonLocked() {
        return false;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return false;
    }

    @Override
    public boolean isEnabled() {
        return false;
    }
}
